﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework.Content;
using System.Xml.Serialization;

namespace Tomahawk.Resources.Materials
{
    public class MaterialReader : ContentTypeReader<SASEffectCollection>
    {
        #region Properties
        public delegate bool InitSASEffectCollectionDelegate(SASEffectCollection collection);
        public static event InitSASEffectCollectionDelegate OnInitEffectCollection;
        #endregion

        protected override SASEffectCollection Read(ContentReader input, SASEffectCollection existingInstance)
        {
            XmlSerializer x = new XmlSerializer(typeof(SASEffectCollection));
            SASEffectCollection output = (SASEffectCollection)x.Deserialize(input.BaseStream);

            foreach (SASEffectTemplate template in output.collection)
            {
                output.EffectTemplates.Add(template.name, template);
            }

            output.collection.Clear();

            if (OnInitEffectCollection != null)
            {
                OnInitEffectCollection(output);
            }

            return output;
        }
    }
}
